<template>
  <chat-list ref="chatListRef" :onSendMessage="onSendMessage" @question-fn="onQuestion" />
</template>
<script setup>
import { ref } from 'vue'
import ChatList from '@/components/Chat/ChatList.vue'
import { Apis } from './composables/useHttp'

const props = defineProps({
  api: {
    type: String,
    default: ''
  },
  params: {
    type: Object,
    default: () => ({ a: 1 })
  }
})

const chatListRef = ref(null)

const onQuestion = (item) => {
  if (!chatListRef.value) return
  chatListRef.value.sendMessage(item)
}

const onSendMessage = ({ data, onMessage }) => {
  return Apis.listenerAdviserMsg({ ...props.params, ...data }, onMessage, props.api)
}
</script>
